from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-09 14:12:58.332763
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 09, Sep, 2021
Time: 14:13:02
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.0789
Nobs: 409.000 HQIC: -46.6126
Log likelihood: 4470.63 FPE: 4.02408e-21
AIC: -46.9621 Det(Omega_mle): 3.23780e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.430672 0.093473 4.607 0.000
L1.Burgenland 0.104312 0.048342 2.158 0.031
L1.Kärnten -0.114071 0.024052 -4.743 0.000
L1.Niederösterreich 0.173488 0.104175 1.665 0.096
L1.Oberösterreich 0.124421 0.101636 1.224 0.221
L1.Salzburg 0.282792 0.050660 5.582 0.000
L1.Steiermark 0.020963 0.067141 0.312 0.755
L1.Tirol 0.108173 0.053089 2.038 0.042
L1.Vorarlberg -0.112267 0.047801 -2.349 0.019
L1.Wien -0.010931 0.092665 -0.118 0.906
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.013964 0.216746 0.064 0.949
L1.Burgenland -0.046488 0.112095 -0.415 0.678
L1.Kärnten 0.037611 0.055771 0.674 0.500
L1.Niederösterreich -0.212811 0.241561 -0.881 0.378
L1.Oberösterreich 0.488989 0.235675 2.075 0.038
L1.Salzburg 0.304539 0.117471 2.592 0.010
L1.Steiermark 0.113148 0.155686 0.727 0.467
L1.Tirol 0.314670 0.123104 2.556 0.011
L1.Vorarlberg 0.000958 0.110842 0.009 0.993
L1.Wien -0.002943 0.214871 -0.014 0.989
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.252337 0.047654 5.295 0.000
L1.Burgenland 0.090619 0.024645 3.677 0.000
L1.Kärnten -0.001550 0.012262 -0.126 0.899
L1.Niederösterreich 0.205388 0.053110 3.867 0.000
L1.Oberösterreich 0.168359 0.051816 3.249 0.001
L1.Salzburg 0.033967 0.025827 1.315 0.188
L1.Steiermark 0.018915 0.034229 0.553 0.581
L1.Tirol 0.067746 0.027066 2.503 0.012
L1.Vorarlberg 0.059930 0.024370 2.459 0.014
L1.Wien 0.105864 0.047242 2.241 0.025
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.179068 0.046596 3.843 0.000
L1.Burgenland 0.048409 0.024098 2.009 0.045
L1.Kärnten -0.006701 0.011990 -0.559 0.576
L1.Niederösterreich 0.140107 0.051931 2.698 0.007
L1.Oberösterreich 0.317484 0.050666 6.266 0.000
L1.Salzburg 0.099942 0.025254 3.957 0.000
L1.Steiermark 0.132155 0.033470 3.949 0.000
L1.Tirol 0.075328 0.026465 2.846 0.004
L1.Vorarlberg 0.055667 0.023829 2.336 0.019
L1.Wien -0.041632 0.046193 -0.901 0.367
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.208164 0.092562 2.249 0.025
L1.Burgenland -0.056524 0.047871 -1.181 0.238
L1.Kärnten -0.034470 0.023817 -1.447 0.148
L1.Niederösterreich 0.119505 0.103159 1.158 0.247
L1.Oberösterreich 0.169625 0.100646 1.685 0.092
L1.Salzburg 0.257994 0.050166 5.143 0.000
L1.Steiermark 0.078606 0.066486 1.182 0.237
L1.Tirol 0.122146 0.052572 2.323 0.020
L1.Vorarlberg 0.115749 0.047335 2.445 0.014
L1.Wien 0.023673 0.091761 0.258 0.796
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.028413 0.071871 0.395 0.693
L1.Burgenland 0.024211 0.037170 0.651 0.515
L1.Kärnten 0.052261 0.018493 2.826 0.005
L1.Niederösterreich 0.211089 0.080099 2.635 0.008
L1.Oberösterreich 0.334320 0.078148 4.278 0.000
L1.Salzburg 0.045629 0.038952 1.171 0.241
L1.Steiermark -0.004296 0.051624 -0.083 0.934
L1.Tirol 0.112734 0.040820 2.762 0.006
L1.Vorarlberg 0.066267 0.036754 1.803 0.071
L1.Wien 0.130164 0.071249 1.827 0.068
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187213 0.087937 2.129 0.033
L1.Burgenland 0.019784 0.045479 0.435 0.664
L1.Kärnten -0.057651 0.022627 -2.548 0.011
L1.Niederösterreich -0.116824 0.098005 -1.192 0.233
L1.Oberösterreich 0.187294 0.095617 1.959 0.050
L1.Salzburg 0.029253 0.047660 0.614 0.539
L1.Steiermark 0.300709 0.063164 4.761 0.000
L1.Tirol 0.487947 0.049945 9.770 0.000
L1.Vorarlberg 0.069934 0.044970 1.555 0.120
L1.Wien -0.104800 0.087177 -1.202 0.229
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160390 0.095471 1.680 0.093
L1.Burgenland -0.007139 0.049375 -0.145 0.885
L1.Kärnten 0.062490 0.024566 2.544 0.011
L1.Niederösterreich 0.189816 0.106401 1.784 0.074
L1.Oberösterreich -0.126139 0.103808 -1.215 0.224
L1.Salzburg 0.238258 0.051743 4.605 0.000
L1.Steiermark 0.157510 0.068575 2.297 0.022
L1.Tirol 0.049195 0.054224 0.907 0.364
L1.Vorarlberg 0.126283 0.048823 2.587 0.010
L1.Wien 0.151941 0.094645 1.605 0.108
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.489500 0.051737 9.461 0.000
L1.Burgenland -0.010028 0.026757 -0.375 0.708
L1.Kärnten -0.009913 0.013312 -0.745 0.456
L1.Niederösterreich 0.202701 0.057660 3.515 0.000
L1.Oberösterreich 0.259710 0.056255 4.617 0.000
L1.Salzburg 0.023408 0.028040 0.835 0.404
L1.Steiermark -0.024654 0.037162 -0.663 0.507
L1.Tirol 0.068032 0.029385 2.315 0.021
L1.Vorarlberg 0.058515 0.026458 2.212 0.027
L1.Wien -0.054206 0.051289 -1.057 0.291
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.020271 0.079694 0.137960 0.135604 0.041179 0.072142 -0.001532 0.175052
Kärnten 0.020271 1.000000 -0.045241 0.126335 0.046993 0.070014 0.455689 -0.094272 0.092630
Niederösterreich 0.079694 -0.045241 1.000000 0.286767 0.082611 0.268539 0.023127 0.140509 0.260753
Oberösterreich 0.137960 0.126335 0.286767 1.000000 0.182344 0.285335 0.156320 0.102288 0.141298
Salzburg 0.135604 0.046993 0.082611 0.182344 1.000000 0.126814 0.057425 0.102035 0.050943
Steiermark 0.041179 0.070014 0.268539 0.285335 0.126814 1.000000 0.131307 0.088372 -0.024266
Tirol 0.072142 0.455689 0.023127 0.156320 0.057425 0.131307 1.000000 0.041110 0.116263
Vorarlberg -0.001532 -0.094272 0.140509 0.102288 0.102035 0.088372 0.041110 1.000000 -0.047419
Wien 0.175052 0.092630 0.260753 0.141298 0.050943 -0.024266 0.116263 -0.047419 1.000000